package com.yoshino.leetcode.interview150.list;

import java.util.LinkedHashMap;
import java.util.Map;

public class LRUCache2 {

    Map<Integer, Integer> map;
    int capacity;
    public LRUCache2(int capacity) {
        map = new LinkedHashMap<Integer, Integer>(capacity, 0.75f, true) {
            @Override
            protected boolean removeEldestEntry(Map.Entry eldest) {
                return map.size() > capacity;
            }
        };
        this.capacity = capacity;
    }
    
    public int get(int key) {
       return map.getOrDefault(key, -1);
    }
    
    public void put(int key, int value) {
        map.put(key, value);
    }
}
